package demo.jdk.features.Base;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author Ranchoz  2018/9/10 15:55
 **/
public class ConsumerExample {


	public static void main(String[] args) {
		peekTest();
	}

	private static void peekTest() {
		List<String> result = Stream.of("one", "two", "three", "four")
				.filter(e -> e.length() > 3)
				.peek(e -> System.out.println("Filtered value: " + e))
				.map(String::toUpperCase)
				.peek(e -> System.out.println("Mapped value: " + e))
				.collect(Collectors.toList());
		System.out.println("$");
		result.forEach(System.out::println);
	}

	private static void flatMap() {
		List<List<Integer>> list = new ArrayList<>();
		List<Integer> list1 = Arrays.asList(new Integer[]{});
		List<Integer> list2 = Arrays.asList(new Integer[]{1});
		List<Integer> list3 = Arrays.asList(new Integer[]{});
		List<Integer> list4 = Arrays.asList(new Integer[]{2, 3});

		list.add(list1);
		list.add(list2);
		list.add(list3);
		list.add(list4);

		List<Integer> result = list.stream().flatMap(x -> x.stream()).collect(Collectors.toList());
		result.forEach(System.out::println);
	}


}
